package net.qhzw.vip.qiyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.qhzw.vip.qiyu.entity.RepairCode;
import net.qhzw.vip.qiyu.entity.SysElectricVehBrand;
import net.qhzw.vip.qiyu.mapper.SysElectricVehBrandMapper;
import net.qhzw.vip.qiyu.model.CarRentalFee;
import net.qhzw.vip.qiyu.service.RepairCodeService;
import net.qhzw.vip.qiyu.service.SysElectricVehBrandService;
import net.qhzw.vip.qiyu.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Service
public class SysElectricVehBrandServiceImpl extends ServiceImpl<SysElectricVehBrandMapper, SysElectricVehBrand>
        implements SysElectricVehBrandService {

    @Autowired
    private RepairCodeService repairCodeService;


    @Autowired
    private SysElectricVehBrandMapper sysElectricVehBrandMapper;


    /***
     * 根据车辆ID获取价格配置
     * @param repairCodeId
     * @return
     */
    @Override
    public SysElectricVehBrand getByRepairCodeId(Long repairCodeId) {
        RepairCode repairCode = repairCodeService.getById(repairCodeId);
        Long electricVehBrandId = repairCode.getElectricVehBrandId();
        Long shopId = SecurityUtils.getLoginUser().getShopId();
        return findById(electricVehBrandId, shopId);
    }


    /***
     * 车辆 电瓶 资费
     * @return
     */
    @Override
    public List<CarRentalFee> findByIdAndRepairCodeId(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return new ArrayList<CarRentalFee>();
        }
        return sysElectricVehBrandMapper.findByIdAndRepairCodeId(ids);
    }

    @Override
    public SysElectricVehBrand findById(Long id, Long shopId) {
        SysElectricVehBrand electricVehBrand = null;
        List<SysElectricVehBrand> electricVehBrands = list(new LambdaQueryWrapper<SysElectricVehBrand>()
                .eq(SysElectricVehBrand::getId, id)
                .eq(SysElectricVehBrand::getShopId, shopId));
        if (!CollectionUtils.isEmpty(electricVehBrands)) {
            electricVehBrand = electricVehBrands.get(0);
        }
        return electricVehBrand;
    }
}
